package it.gtd.swimpool.model.entity;

import com.google.common.annotations.Beta;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

import static com.google.common.base.Preconditions.checkNotNull;

@Embeddable
@Beta
class FeedbackId implements Serializable {
    @ManyToOne
    private User author;

    @ManyToOne
    private User target;

    @ManyToOne
    private Skill skill;

    @Basic
    @Column(name = "created_at")
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationDate;

    public FeedbackId() {
        creationDate = new Date();
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public User getAuthor() {
        return author;
    }

    public void setAuthor(User author) {
        checkNotNull(author, "author can't be null");

        this.author = author;
    }

    public User getTarget() {
        return target;
    }

    public void setTarget(User target) {
        checkNotNull(target, "target can't be null");

        this.target = target;
    }

    public Skill getSkill() {
        return skill;
    }

    public void setSkill(Skill skill) {
        checkNotNull(skill, "skill can't be null");

        this.skill = skill;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof FeedbackId)) return false;

        FeedbackId that = (FeedbackId) o;

        if (!author.equals(that.author)) return false;
        if (!skill.equals(that.skill)) return false;
        if (!target.equals(that.target)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = author.hashCode();
        result = 31 * result + target.hashCode();
        result = 31 * result + skill.hashCode();
        return result;
    }
}
